using System;
using FluentTests.Framework.VerbExtensions;
using FluentTests.NUnit;
using NUnit.Framework;

namespace FluentTests.Tests
{
    [TestFixture]
    public class ReferenceTestsUsingNUnit
    {
        [Test]
        public void TestEqualTo()
        {
            string obj1 = "test" + 1;
            string obj2 = "t" + "est" + 1;
            Ensure.That(obj1).Is.EqualTo(obj2);
        }

        [Test]
        public void TestInstanceOf()
        {
            Ensure.That("").Is.InstanceOf(typeof (string));
        }
        [Test]
        public void TestInstanceOfGenerics()
        {
            Ensure.That("").Is.InstanceOfType<string>();
        }
        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestInstanceOfGenericsFails()
        {
            Ensure.That("").Is.InstanceOfType<int>();
        }
        [Test]
        public void TestNotInstanceOfGenerics()
        {
            Ensure.That("").Is.Not.InstanceOfType<int>();
        }
        [Test]
        [ExpectedException(typeof(AssertionException))]
        public void TestNotInstanceOfGenericsFails()
        {
            Ensure.That("").Is.Not.InstanceOfType<string>();
        }

        [Test]
        [ExpectedException(typeof (AssertionException))]
        public void TestInstanceOfFails()
        {
            Ensure.That("").Is.Not.InstanceOf(typeof (string));
        }

        [Test]
        [ExpectedException(typeof (AssertionException), ExpectedMessage = "Actual value is  equal to expected value")]
        public void TestIsNotEqualFails()
        {
            Ensure.That(3).Is.Not.EqualTo(3);
        }

        [Test]
        public void TestIsNullUsingVerb()
        {
            Ensure.That("").Is.Not.Null();
        }

        [Test]
        [ExpectedException(typeof (AssertionException))]
        public void TestIsNullUsingVerbAndDoubleNegation()
        {
            Ensure.That("").Is.Not.Not.Null();
        }

        [Test]
        [ExpectedException(typeof (AssertionException))]
        public void TestIsNullUsingVerbFailing()
        {
            Ensure.That(null).Is.Not.Null();
        }

        [Test]
        public void TestNotEqualTo()
        {
            string obj1 = "test" + 1;
            string obj2 = "t" + "test" + 1;
            Ensure.That(obj1).Is.Not.EqualTo(obj2);
        }

        [Test]
        public void TestNotInstanceOf()
        {
            Ensure.That("").Is.Not.InstanceOf(typeof (Int32));
        }

        [Test]
        [ExpectedException(typeof (AssertionException))]
        public void TestNotInstanceOfFails()
        {
            Ensure.That("").Is.InstanceOf(typeof (Int32));
        }


        [Test]
        public void TestReferenceEquality()
        {
            string obj1 = "test";
            string obj2 = obj1;
            Ensure.That(obj1).Are.SameAs(obj2);
        }


        [Test]
        public void TestReferenceNonEquality()
        {
            string obj1 = "test";
            string obj2 = "test2";
            Ensure.That(obj1).Are.Not.SameAs(obj2);
        }


        [Test]
        [ExpectedException(typeof (AssertionException))]
        public void TestReferenceEqualityFails()
        {
            string obj1 = "test";
            string obj2 = "test2";
            Ensure.That(obj1).Is.SameAs(obj2);
        }

        [Test]
        public void TestAndExpression()
        {
            object obj = "test string";
            Ensure.That(obj).Is.InstanceOfType<string>().And(a => a.ToString()).Has.MoreThanZeroCharacters();
        }
    }
}